<template>
	<div>
		<div class="item1">
			<span class="item1_title">点击下面按钮免费发布帖子
			</span>
			<button class="item1_button" @click="onBtnClick()">{{btnText}}</button>

		</div>

		<div class="item2">
			<span class="item2_title">
				扫码下载网站客户端
			</span>
			<img src="../../../static/ads/erweima.png" style="width: 11.875rem;" />

		</div>

		<view class="item3" v-show="isShowNew">
			<span class="item3_title">
				最新帖子
			</span>
			<view v-for="cp in datas">
				<a @click="showCpDetail(cp)">{{cp.CHANPIN_APPMINGZI}}</a>
			</view>

		</view>

		<div class="item3">
			<span class="item3_title">
				热门帖子
			</span>
			<view v-for="cp in hots">
				<a @click="showCpDetail(cp)">{{cp.CHANPIN_APPMINGZI}}</a>
			</view>

		</div>

		<!-- <div class="item3">
			<img src="../../../../static/ads/ad1.gif" />
			<img src="../../../../static/ads/ad2.gif" />
			<img src="../../../../static/ads/ad3.gif" />
			<img src="../../../../static/ads/ad1.gif" />
			<img src="../../../../static/ads/ad3.gif" />
			<img src="../../../../static/ads/ad2.gif" />
		</div> -->
	</div>
</template>

<script>
	export default {
		data() {
			return {
				datas: [],
				hots: [],
				isShowNew: true,
				btnText:"发布信息",
				type:"type",
			}
		},
		props: {
			msg: String
		},
		created() {
			//注册全局监听事件，搜索后更新界面数据 
			uni.$on('showNews', (res) => {
				this.datas = res;
			})

		},
		mounted() {
			this.$nextTick(() => {
				this.getHot();
			});

		},
		methods: {
			showbtnText(text,type){
				this.btnText=text;
				this.type=type;
			},
			onBtnClick() {
				if (this.$PublicData.getUserdata() == null || this.$PublicData.getUserdata().userName == null) {
					this.$Utils.showToast("您还没有登录，请先登录!");
				} else {
					console.log("555555555555555555555: "+this.type);
					uni.$emit(this.type, 0);
				}

			},
			async getHot() {
				try {
					const res = await this.$getData({
						url: this.$apis.getHotCp
					})
					this.hots = res.data.data;

				} catch (e) {
					console.log("eee: ", e);
				}
			},
			hidNewCpInfo() {
				this.isShowNew = false;
			},
			async addck(id){
				try {
					const res = await  this.$postData({
						url:this.$apis.addCK,
						data: {
							CHANPIN_ID: id,
						}
					})
					console.log(res);
				
				} catch (e) {
					console.log("eee: ", e);
					
				}
			},
			//跳转到产品详情页面
			showCpDetail(cp) {
				this.addck(cp.CHANPIN_ID);
				uni.navigateTo({
					url: '../chanping/ChanpingDetail',
					success: function(res) {
						res.eventChannel.emit('setCp', cp)

					}
				})


			}


		},
	}
</script>

<style>
	
	a:hover {
		background: #F99B15;
		color: #FFFFFF!important;
	}

	.item1 {
		justify-content: center;
		align-items: center;
		margin-top: 0.2125rem;
		align-items: center;
		padding: 0.3125rem;
		word-wrap: break-word;
		overflow: hidden;
		word-break: break-all;
		flex-direction: column;
		display: flex;
		min-height: 6.875rem;
		border: 0.0625rem solid #E5E5E5;
		border-radius: 0.1875rem;
	}

	.item1 a :hover {
		background: #F0AD4E;
	}

	.item1_title {
		font-size: 0.9125rem;
		color: #333333;
	}

	.item1_button {
		letter-spacing: 0.2rem;
		margin-top: 0.8125rem;
		font-size: 1rem;
		width: 11.875rem;
		border: 0.0625rem solid #F99B15;
		border-radius: 0.3125rem;
		text-align: center;
		justify-content: center;
		align-items: center;
		display: flex;
		height: 2.5rem;
		background: #F99B15;
		color: #FFFFFF;
	}
	
	.item1_button :hover{
		 cursor:pointer;
	}
	
	

	.item2 {
		margin-top: 0.8125rem;
		align-items: center;
		padding: 0.3125rem;
		word-wrap: break-word;
		overflow: hidden;
		word-break: break-all;
		flex-direction: column;
		display: flex;
		height: 220px;
		border: 0.0625rem solid #E5E5E5;
		border-radius: 0.1875rem;
	}

	.item3 {
		margin-top: 0.8125rem;
		align-items: center;
		padding: 0.3125rem;
		word-wrap: break-word;
		overflow: hidden;
		word-break: break-all;
		flex-direction: column;
		display: flex;
		min-height: 6.875rem;
		border: 0.0625rem solid #E5E5E5;
		border-radius: 0.1875rem;
	}

	.item2_title {
		width: 100%;
		align-items: center;
		display: flex;
		align-items: center;
		padding-bottom: 0.3125rem;
		font-size: 0.9375rem;
		color: #333333;
		border-bottom: 0.0625rem solid #E5E5E5;
	}

	.item3_title {
		align-self: center;
		width: 100%;
		display: flex;
		align-items: center;
		padding-bottom: 0.3125rem;
		display: flex;
		font-size: 0.9875rem;
		font-weight: bold;
		color: #F99B15;
		border-bottom: 0.0625rem solid #E5E5E5;

	}

	.item3 a {
		color: #333333;
		height: 2.125rem;
		display: block;
		line-height: 2.125rem;
		font-size: 0.875rem;
		letter-spacing: 0.125rem;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		width: 12.5rem;
		border-bottom: 0.0625rem solid #E5E5E5;
	}

	.item3 img {
		margin-top: 0.3125rem;
	}
</style>
